﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO_HealthInsurance;



namespace DAO_HealthInsurance
{
   public class DAOCompany:ConnectDatabase
    {
      public SqlCommand Cmd;
      public DTOCompanyDetail objCom;
       public DataTable ListCompany() {
           try
           {
               OpenConnect();
               Cmd = new SqlCommand("ListCompany",Conn);
               Cmd.CommandType = CommandType.StoredProcedure;
               SqlDataAdapter da = new SqlDataAdapter(Cmd);
               DataTable dt = new DataTable("CompanyDetails");
               da.Fill(dt);
               CloseConnect();
               return dt;
           }
           catch (Exception ex)
           {
               throw ex;
           }
          
       }
     
       public int InsertCompany(DTOCompanyDetail objCom) {
           int Result = 0;
           try
           {
               OpenConnect();
               Cmd = new SqlCommand("InsertCompany", Conn);
               Cmd.CommandType = CommandType.StoredProcedure;
               Cmd.Parameters.Add("@CompanyName",SqlDbType.VarChar,50).Value = objCom.CompanyName;
               Cmd.Parameters.Add("@CompanyAddress",SqlDbType.VarChar,150).Value=objCom.Address;
               Cmd.Parameters.Add("@CompanyPhone",SqlDbType.VarChar,20).Value = objCom.Phone;
               Cmd.Parameters.Add("@CompanyUrl", SqlDbType.VarChar, 50).Value = objCom.CompanyUrl;
               Result = Cmd.ExecuteNonQuery();
               CloseConnect();
           }
           catch (Exception ex)
           {

               throw ex;
           }
           return Result;
       }

       public int DeleteCompany(DTOCompanyDetail objCom) {
           int Result = 0;
           try
           {
               OpenConnect();
               Cmd = new SqlCommand("DeleteCompany", Conn);
               Cmd.CommandType = CommandType.StoredProcedure;
               Cmd.Parameters.Add("@CompanyID", SqlDbType.Int).Value = objCom.CompanyId;
               Result = Cmd.ExecuteNonQuery();
               CloseConnect();
           }
           catch (Exception ex)
           {

               throw ex;
           }
           return Result;
       
       }
       public int UpdateCompanyInfo(DTOCompanyDetail objCom) {
           int Result = 0;
           try
           {
               OpenConnect();
               Cmd = new SqlCommand("UpdateCompany", Conn);
               Cmd.CommandType = CommandType.StoredProcedure;
               Cmd.Parameters.Add("@CompanyID", SqlDbType.VarChar, 50).Value = objCom.CompanyId;
               Cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50).Value = objCom.CompanyName;
               Cmd.Parameters.Add("@CompanyAddress", SqlDbType.VarChar, 150).Value = objCom.Address;
               Cmd.Parameters.Add("@CompanyPhone", SqlDbType.VarChar, 20).Value = objCom.Phone;
               Cmd.Parameters.Add("@CompanyUrl", SqlDbType.VarChar, 50).Value = objCom.CompanyUrl;
               Result = Cmd.ExecuteNonQuery();
               CloseConnect();
           }
           catch (Exception ex)
           {
               
               throw ex;
           }
           return Result;
       
       }

       public DataTable GetCompanyById(DTOCompanyDetail objCom) {
           try
           {
               Cmd = new SqlCommand("GetCompanyById", Conn);
               Cmd.CommandType = CommandType.StoredProcedure;
               Cmd.Parameters.Add("@CompanyID", SqlDbType.VarChar, 50).Value = objCom.CompanyId;
               SqlDataAdapter da = new SqlDataAdapter(Cmd);
               DataTable dt = new DataTable("CompanyDetails");
               da.Fill(dt);
               return dt;
           }
           catch (Exception ex)
           {
               throw ex;
           }
           
       }
    }
}
